import 'package:flutter_deer/database/database_manager.dart';
import 'package:flutter_deer/dl/dl.dart';
import 'package:objectbox/objectbox.dart';

@Entity()
class MqttMsgModel {
  @Id() // 自增主键
  int id = 0;

  @Unique(onConflict: ConflictStrategy.fail)
  String msgId = '';
  String msgContent = '';//id type subType Data
  String subType = '';
  String type = '';

  // String timestamp = '';
  String localTimestamp = '';

  MqttMsgModel();

  @override
  String toString() {
    return 'MqttMsgModel{id: $id, msgId: $msgId, msgContent: $msgContent, subType: $subType, type: $type, localTimestamp: $localTimestamp}';
  }

  // 存储到数据库
  Future<void> save() async {
    final store = getIt<ObjectIdBox>().store;
    final box = store.box<MqttMsgModel>();
    box.put(this);
  }


}


// factory GetAllGoodsList.fromJson(Map<String, dynamic> json) => $GetAllGoodsListFromJson(json);

  // Map<String, dynamic> toJson() => $GetAllGoodsListToJson(this);

  // /// 删除所有
  // static Future<void> deleteAll() async {
  //   final store = getIt<ObjectIdBox>().store;
  //   final box = store.box<GetAllGoodsList>();
  //   box.removeAll();
  // }
  //
  // /// 保存到数据库
  // static Future<void> saveAll(List<GetAllGoodsList> list) async {
  //   // 保存到数据库
  //   final store = getIt<ObjectIdBox>().store;
  //   final box = store.box<GetAllGoodsList>();
  //   box.putMany(list);
  // }

/*
header
{
   encode: "GZIP",
   id: "1000200000093863490",
   subType: "WORK_CLASS_KNOT_TICKET_CONFIG",
   timestamp: "1751013403853",
   type: "RECEIPT_SETTING_NOTICE"
}
{
   data: "{"configKey":"WORK_CLASS_KNOT_TICKET_CONFIG"}",
   duration: "10",
   id: "1000200000000414842",
   mchCode: "NY101171184177",
   subType: "WORK_CLASS_KNOT_TICKET_CONFIG",
   type: "RECEIPT_SETTING_NOTICE"
}
*/